program=$1
title(){
	clear
	echo "Memory used by $program. Ctl-C to exit"
	echo "--------------------------------------"
}
while true; do
	pid=$(ps ux|grep $program | grep -v grep|awk '{print $2}')
	if [ "$pid" ];then
		if [ "$pid" != "$oldpid" ];then
			oldpid=$pid
			max=0
		fi		
		map=$(pmap $pid |grep total|awk '{print $2}')
		memory=$(echo $map | cut -d"K" -f1)
		if [ $memory -gt $max ];then
			max=$memory
		fi
		title
		echo "Using: $map   Max used: $(($max/1024)) MB"
		sleep 1
	fi
done
